<template>
  <div class="item-list__content">
    <template v-if="list.length">
      <div class="item-list__content__signle"
           v-for="(item,index) in list"
           :key="index">
        <div class="cover-img"
             v-if="showCover(item)"
             :style="`background-image:url(${item.image.url});`">
          <div class="category">
            <router-link class="router-link-title"
                         :to="{
                           name:'topics',
                           query:{
                             cate_id: `${item.cate.id}`
                           }
                         }">
              {{item.cate.name}}
            </router-link>
          </div>
        </div>
        <div class="content">
          <h4 class="title">
            <router-link class="router-link-title"
                         :target="target"
                         :to="{
                            name:'article',
                            params:{
                              id: `${item.id}`
                            }
                         }">
              {{item.title}}
            </router-link>
            <div class="fettle">
            </div>
          </h4>
          <div class="tag-list">
            <span v-for="tag in item.tag_list"
                  :key="tag.id">#{{tag.name}}</span>
          </div>
          <div class="signle__body">{{item.summary}}</div>
          <div class="footer">
            <div class="part">
              <span>查看:{{ item.view_nums }}</span>
              <span>评论:{{ item.comment_nums }}</span>
              <span>赞:{{ item.approve_nums }}</span>
              <span>{{ item.created_at | timeFilter }}</span>
            </div>
            <div class="more-look">
              <router-link class="none-class-link"
                           target="_blank"
                           :to="{
                            name:'article',
                            params:{
                              id: `${item.id}`
                            }
                         }">
                阅读全文>
              </router-link>
            </div>
          </div>
        </div>
      </div>
    </template>
    <template v-else>
      <div class="item-list__content__empty"
           :class={search_empty:search}>
        <span>暂无内容</span>
      </div>
    </template>
  </div>
</template>
<script>
export default {
  name: 'item-list',
  props: {
    list: {
      type: Array,
      default: () => []
    },
    scenes: {
      type: String,
      default: 'list'
    },
    target: {
      type: String,
      default: '_self'
    }
  },
  computed: {
    search () {
      return this.scenes === 'search'
    }
  },
  methods: {
    showCover (item) {
      return typeof (item.image) === 'object' && item.image.url
    }
  }
}
</script>
<style lang="scss" scoped>
.item-list__content {
  display: flex;
  align-content: center;
  flex-direction: column;
  &__signle {
    display: flex;
    position: relative;
    background-color: #fff;
    border-bottom: 1px solid #f6f6f6;
    padding: 10px 0px;
    justify-content: space-between;
    align-items: center;
    height: 160px;
    &:last-child {
      border-bottom: 1px solid transparent;
    }
    &::before {
      -webkit-transition: width 0.2s ease-out;
      transition: width 0.2s ease-out;
      left: 0;
      content: "";
      position: absolute;
      bottom: 0;
      width: 0;
      border-bottom: 1px solid #409eff;
    }
    &:hover {
      &::before {
        width: 100%;
      }
      .content {
        .footer {
          .more-look {
            visibility: inherit;
          }
        }
      }
    }
    .cover-img {
      display: flex;
      width: 160px;
      height: 100%;
      margin-right: 12px;
      position: relative;
      background-size: cover;
      background-position: 50%;
      transition: 0.3s ease-out;
      .category {
        cursor: pointer;
        position: absolute;
        top: 10px;
        left: 10px;
        font-size: 12px;
        line-height: 20px;
        background-color: rgba(0, 0, 0, 0.53333);
        padding: 0 5px;
        min-width: 47px;
        height: 20px;
        text-align: center;
        a {
          color: #fff;
        }
      }
    }
    .content {
      display: flex;
      flex: 1;
      flex-direction: column;
      text-align: left;
      font-size: 15px;
      margin: 0;
      .title {
        display: flex;
        justify-content: space-between;
        line-height: 20px;
        margin: 0;
        a {
          cursor: pointer;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 1;
          -webkit-box-orient: vertical;
        }
        .fettle {
          width: 80px;
        }
      }
      .tag-list {
        line-height: 18px;
        padding: 3px 0;
        font-size: 13px;
        cursor: pointer;
        color: #adadad;
        :nth-child(n + 2) {
          margin-left: 5px;
        }
      }
      .signle__body {
        display: flex;
        overflow: hidden;
        height: 88px;
        line-height: 22px;
        padding: 2px 0 4px 0;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 4;
        -webkit-box-orient: vertical;
      }
      .footer {
        line-height: 22px;
        font-size: 13px;
        display: flex;
        justify-content: space-between;
        :nth-child(n + 2) {
          margin-left: 10px;
        }
        .more-look {
          cursor: pointer;
          visibility: hidden;
          color: #409eff;
        }
      }
    }
  }
  &__empty {
    display: flex;
    justify-content: center;
    color: #adadad;
  }
  .search_empty {
    margin-top: 10px;
  }
}
</style>
